package com.chat.datea.acitivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.ImageView;

import com.chat.datea.R;
import com.chat.datea.base.BaseActivity;

import cn.jpush.android.api.JPushInterface;

/**
 * Created by dllo on 15/10/14.
 */
public class WelcomeActivity extends BaseActivity {

    private final int SPLASH_DISPLAY_LENGHT = 3000;
    private SharedPreferences preferences;
    private SharedPreferences.Editor editor;
    private ImageView biz_datea_img;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        biz_datea_img = (ImageView) findViewById(R.id.biz_datea_img);
        preferences = getSharedPreferences("phone", Context.MODE_PRIVATE);
        AlphaAnimation animation = new AlphaAnimation(1.0f, 1.0f);
        animation.setDuration(1500);
        biz_datea_img.startAnimation(animation);

        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        if (preferences.getBoolean("firstStart", true)) {
                            editor = preferences.edit();
                            // 将登陆标识设置为false，下次登录时不再显示引导界面
                            editor.putBoolean("firstStart", false);
                            editor.commit();
                            Intent intent = new Intent(WelcomeActivity.this, SplashActivity.class);
                            startActivity(intent);
                            finish();
                        } else {
                            Intent intent = new Intent(WelcomeActivity.this, com.chat.datea.ui.MainActivity.class);
                            startActivity(intent);
                            finish();
                        }
                    }
                }, SPLASH_DISPLAY_LENGHT);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        JPushInterface.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        JPushInterface.onPause(this);
    }
}

